/*
    Author: Christopher Diggins
    License: MIT Licence 1.0
    Website: http://www.heron-language.com
*/

#ifndef HERON_TO_LLSCHEME_POST_PROCESS_HPP
#define HERON_TO_LLSCHEME_POST_PROCESS_HPP

namespace heron_to_lls_pp
{
	using namespace lls;

	void ConvertInvokes(SExpr* x) {
		if (x->Is<Apply>() && x->As<Apply>()->Func()->Is<GetField>()) {
			Apply* app = x->As<Apply>();
			GetField* rfs = app->Func()->As<GetField>();
			Invoke* invk = new Invoke();
			invk->AddChild(rfs->Object()->Clone());
			invk->AddChild(rfs->GetNameExpr()->Clone());
			invk->AddChild(app->GetArgs()->Clone());
			Replace(x, invk);
		}
		
		x->ForEach(ConvertInvokes);
	}

	void ConvertListPrimitives(SExpr* x) {
		// TODO: 
	}

	void PostProcess(SExpr* x) {
		ConvertInvokes(x);
		ConvertListPrimitives(x);
	}
}

#endif
